package com.boesch.electroOffice.dataaccess.mapper;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import com.boesch.electroOffice.model.electroOffice.Measurement;
import com.boesch.electroOffice.utils.DateUtils;

/**
 * This class mappes the rows from database to a Measurement object.
 * 
 * @author Ralph Koster
 *
 */
public class MeasurementMapper implements RowMapper<Measurement>, Serializable {

	private static final long serialVersionUID = -8053615700737421666L;

	/**
	 * Mapps all rows from database to a Measurement object.
	 * 
	 * @see org.springframework.jdbc.core.RowMapper
	 */
	public Measurement mapRow(ResultSet rs, int rowNum) throws SQLException {
		Measurement measurement = new Measurement();

		measurement.setId(rs.getInt("Id_pk"));
		measurement.setObject(rs.getString("Object"));
		measurement.setEnergyMeterNumber(rs.getString("Energymeternumber"));
		measurement.setLocation(rs.getString("Location"));
		measurement.setMeasurementDate(DateUtils.convertDateToLocalDate(rs.getDate("Measurementdate")));
		measurement.setLrUserId(rs.getLong("LrUserId"));
		measurement.setCreatedBy(rs.getString("Createdby"));
		measurement.setCreatedAt(DateUtils.convertTimestampToLocalDateTime(rs.getTimestamp("Createdat")));
		measurement.setModifiedBy(rs.getString("Modifiedby"));
		measurement.setModifiedAt(DateUtils.convertTimestampToLocalDateTime(rs.getTimestamp("Modifiedat")));
		measurement.setVersion(rs.getInt("Version"));

		return measurement;
	}
}
